
const Article = require('../model/Article')
const User = require('../model/User')
const Image = require('../model/Image')

async function getCollectForUser(arrTe) {
    let collectList = {
        statusCode: 0,
        statusMsg: []
    }
    for (const item of arrTe) {
        let tem = {
            list: Object,
            user: Object
        }
        let artcileTem = (await Article.findOne({
            where: {
                articleId: item.articleId
            }
        })).dataValues
        if(!artcileTem) {
            continue
        }
        let user = (await User.findOne({
            where: {
                userId: artcileTem.userId
            }
        })).dataValues
        let image = await  (await Image.findOne({
            where: {
                imageId: user.portraitId
            }
        })).dataValues
        user.image = image
        tem.list = artcileTem
        tem.user = user
        collectList.statusMsg.push(tem)
    }
    collectList.statusCode = 1
    return collectList
}

module.exports = getCollectForUser